package com.xuecheng.content.controller;

import com.xuecheng.api.content.TeacherApi;
import com.xuecheng.api.content.model.CourseTeacherDTO;
import com.xuecheng.api.content.model.CourseTeacherVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.CourseTeacherConvert;
import com.xuecheng.content.service.CourseTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程-教师关系表 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
//@RequestMapping("courseTeacher")
public class CourseTeacherController implements TeacherApi {

    @Autowired
    private CourseTeacherService courseTeacherService;


    //获取课程教师信息
    @Override
    @GetMapping("courseTeacher/list/{courseBaseId}")
    public List<CourseTeacherDTO> queryTeacher(@PathVariable Long courseBaseId) {

        Long companyId = SecurityUtil.getCompanyId();
        return courseTeacherService.queryTeacher(courseBaseId, companyId);
    }


    //内容管理教師更改或者新增
    @Override
    @PostMapping("courseTeacher")
    public CourseTeacherDTO insertAndUpdateTeacherDTO(@RequestBody CourseTeacherVO curseTeacherVO) {
        Long companyId = SecurityUtil.getCompanyId();
        CourseTeacherDTO courseTeacherDTO = CourseTeacherConvert.INSTANCE.vo2dto(curseTeacherVO);
        return courseTeacherService.insertAndUpdateTeacherDTO(courseTeacherDTO, companyId);

//        return null;
    }

    //课程教师删除操作
    @Override
    @DeleteMapping("/courseTeacher/course/{courseBaseId}/{courseTeacherId}")
    public void deleteTeacher(@PathVariable Long courseBaseId,@PathVariable Long courseTeacherId) {
        Long companyId = SecurityUtil.getCompanyId();
        courseTeacherService.deleteTeacher(courseBaseId,courseTeacherId,companyId);

    }
}
